package com.czkt.shop.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.czkt.shop.mapper.ShopCartMapper;
import com.czkt.shop.pojo.ShopCart;
import com.czkt.shop.service.IShopCartService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ShopCartServiceImpl extends ServiceImpl<ShopCartMapper, ShopCart> implements IShopCartService {

    @Override
    public List<ShopCart> list(Long uid) {
        LambdaQueryWrapper<ShopCart> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(uid != null && uid != 0,ShopCart::getUserId,uid);
        return baseMapper.selectList(queryWrapper);
    }

    @Override
    public Long count(Integer uid) {

        LambdaQueryWrapper<ShopCart> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ShopCart::getUserId,uid);

        return baseMapper.selectCount(queryWrapper);
    }

    @Override
    public ShopCart selectOne(Long skuId) {
        LambdaQueryWrapper<ShopCart> queryWrapper = new LambdaQueryWrapper<>();

        queryWrapper.eq(ShopCart::getSkuId,skuId);

        return baseMapper.selectOne(queryWrapper);
    }
}